const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
    // LIFE-CYCLE CALLBACKS:
    game_model_ts = null;
    game_net_ts = null;
    voice_back:any = null;      //背景音乐控件
    btn_voice_flag = false;     //背景音乐的按键
    voice_status = true;        //背影音乐的状态
    btn_invite_flag = false;    //邀请好友的按键

    onLoad () {
        //数据层   
        this.game_model_ts = this.node.getComponent('game_model');  

        //网络层(主要用于长连接，短连接可以不用管)  
        this.game_net_ts = this.node.getComponent('game_net');  
        
        console.log("this.game_model_ts.more_game:",this.game_model_ts.more_game);
        console.log("cc.game_config",cc.game_config)
        //开启背景音乐
        console.log(this.game_model_ts.back_music);
        this.voice_back = window['wx'].createInnerAudioContext();
        this.voice_back.src = this.game_model_ts.back_music; // src 可以设置 http(s) 的路径，本地文件路径或者代码包文件路径
        this.voice_back.loop = true;//循环播放，详细查看微信的API
        this.voice_back.play();
    }

    start () {
        
        cc.wx.meun_share(this.game_model_ts.wx_share_title,this.game_model_ts.wx_share_image,'');//开启头部按钮分享
    }

    music_control(){        
        if(this.btn_voice_flag == true)
        {
            return;
        }
        else
        {
            console.log('music_control');
            this.btn_voice_flag = true;
            if(this.voice_status == true)
            {
                this.voice_back.stop();
                this.voice_status = false;
                this.node.getChildByName('music').getChildByName('music_close').active = true;
                this.node.getChildByName('music').getChildByName('music_open').active = false;
                
            }
            else
            {
                this.voice_back.play();
                this.voice_status = true;
                this.node.getChildByName('music').getChildByName('music_open').active = true;
                this.node.getChildByName('music').getChildByName('music_close').active = false;
                
            }
            this.btn_voice_flag = false;             
        }
    }

    async invite_friend(){
        console.log(this.game_model_ts.wx_share_title);
        console.log(this.game_model_ts.wx_share_image);
        var res = cc.wx.btn_share(this.game_model_ts.wx_share_title,this.game_model_ts.wx_share_image,'');
        console.log(res);       
    }

    btn_more_game(){
        cc.utils.show_more_game();     
    }

    btn_qian_dao(){
        cc.utils.show_qian_dao();        
    }

    btn_li_bao(){
        cc.utils.show_li_bao();
    }

    btn_rank(){
        cc.utils.show_rank();
    }



    // update (dt) {}
}
